package mumu.android.lib.view.webview;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Handler;
import android.os.Message;
import android.support.v4.content.LocalBroadcastManager;
import android.widget.Toast;

public class WebViewInterface {
	Context mContext;
	Handler mHandler = new Handler() {

		@Override
		public void dispatchMessage(Message msg) {
			int what=msg.what;
			Toast.makeText(mContext, "哈哈", 1000).show();
		}

	};

	public WebViewInterface(Context mContext) {
		this.mContext = mContext;
	}

	/**
	 * 获取设备号
	 * 
	 * @return
	 */
	public String getDeviceId() {
		Toast.makeText(mContext, "哈哈a",Toast.LENGTH_SHORT).show();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		mHandler.sendEmptyMessage(0);
		return "1212";
		// TelephonyManager telephonyManager = (TelephonyManager)
		// mContext.getSystemService(Context.TELEPHONY_SERVICE);
		// return telephonyManager.getDeviceId();
	}

	/**
	 * 获取设备号
	 * 
	 * @return
	 */
	public Integer getVersion() {
		int versionCode = 0;
		PackageManager pm = mContext.getPackageManager();
		PackageInfo pi;
		try {
			pi = pm.getPackageInfo(mContext.getPackageName(), 0);
			versionCode = pi.versionCode;
		} catch (NameNotFoundException e1) {
			e1.printStackTrace();
		}
		return versionCode;
	}

	/**
	 * 获取设备号
	 * 
	 * @return
	 */
	public String getPackageName() {
		return mContext.getPackageName();
	}

	/**
	 * 获取设备号
	 * 
	 * @return
	 */
	public String getStr(int i) {
		return i + "  =interface";
	}

	public void domReady() {

		LocalBroadcastManager.getInstance(mContext).sendBroadcast(new Intent(WebViewFrame.WEBVIEWBOASTCAST_STRING));
	}

}
